nextrow=SCREENWIDTH; /* Set next row to be scrolled into (to the right) */
/* The main loop */
for(;;)
{
if(gs_joystick(0)&(JOY_BUTTON1|JOY_BUTTON2))break; /* Poll mouse port - click to exit */
joy=gs_joystick(1); /* Poll joystick port */
/* If joystick is moved RIGHT */
if(joy&JOY_RIGHT&&nextrow<MAPWIDTH)
{
/* Wait until system has updated the last scroll we gave it before proceeding */
while(display.flags&GSV_SCROLL1);
/* Draw tiles */
x = gsvp->xoff % 16;
if(x){y=nextrow-1;BlitRow((WORD)((gsvp->xoff-16)-x),y);} /* If current x pos is not on even word, blit tiles _behind_ current pos. */
else {BlitRow((WORD)(gsvp->xoff+320),nextrow);nextrow++;} /* If it is, blit tiles _ahead_ of current pos, and advance nextrow */
/* Scroll */
if(gsvp->xoff>=(352-SCROLLSPEED))
gs_scroll_vp(&display,0,-(336-SCROLLSPEED),0,1); /* Jump back (more than a full screen - there's an extra row in there) if reached end of bitmap */
else
gs_scroll_vp(&display,0,SCROLLSPEED,0,1); /* Otherwise just scroll one "step" */
}
/* If joystick is moved LEFT */
else if(joy&JOY_LEFT&&nextrow>20)
{
/* Wait till previous scroll is actually done */
while(display.flags&GSV_SCROLL1);
/* Draw tiles */
x = gsvp->xoff % 16;
if(x){y=nextrow-21;if(y>=0)BlitRow((WORD)((gsvp->xoff+320)+(16-x)),y);if(x==SCROLLSPEED)nextrow--;} /* Only blit the tiles if NOT less than tilerow 0 (y>=0) */